package com.anjubao.parking.municipal.roadside.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.roadside.form.VideoPileForm;
import com.anjubao.parking.municipal.roadside.service.DeviceVideoPileService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author :anjubao
 * 同步设备
 */
@RestController
@RequestMapping("/sync/device")
public class DeviceVideoPileController {

    private static final Logger logger = LoggerFactory.getLogger(DeviceVideoPileController.class);
    @Autowired
    private DeviceVideoPileService deviceVideoPileService;

    /**
     * 新增|修改 设备
     *
     * @param videoPileForm
     * @return
     */
    @PostMapping(value = "")
    @ApiOperation(value = "同步视频桩操作", notes = "", code = 2000)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "videoPileForm", required = true, dataType = "VideoPileForm", paramType = "body")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "操作失败"),
    })
    public ApiResult syncVideoPile(@RequestBody VideoPileForm videoPileForm) {
        logger.info("【同步视频桩】，视频桩code:{}", videoPileForm.getDeviceCode());
        deviceVideoPileService.syncVideoPile(videoPileForm);
        return ApiResult.success();
    }

    /**
     * 删除设备
     *
     * @param deviceID
     * @return
     */
    @DeleteMapping(value = "/{deviceID}")
    @ApiOperation(value = "删除视频桩操作", notes = "", code = 2000)
    @ApiResponses(value = {
            @ApiResponse(code = 5000, message = "操作失败"),
    })
    public ApiResult deleteVideoPile(@NotNull @PathVariable("deviceID") Long deviceID) {
        deviceVideoPileService.deleteVideoPile(deviceID);
        return ApiResult.success();
    }
}
